# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import APIRouter, UploadFile, Form, Request
from hypertext import R, response_json
from apps.admin.service.upload_service import UploadService
from apps.admin.schemas.common_schema import UploadResultVo

router = APIRouter(prefix="/upload", tags=["上传接口"])


@router.post("/files", summary="上传文件", response_model=R[UploadResultVo])
@response_json
async def files(
        request: Request,
        file: UploadFile,
        cid: int = Form(ge=0, default=0),
        scene: str = Form(default="image"),
        is_attach: int = Form(ge=0, le=1, default=1),
) -> UploadResultVo:
    admin_id: int = request.state.admin_id
    return await UploadService.file(file, cid, scene, is_attach, admin_id)
